#include <iostream>

class Complex // 复数类
{
public:
    Complex() : real(0), vir(0) {}
    Complex(int real, int vir) : real(real), vir(vir) {}
    void show()
    {
        std::cout << real << "+" << vir << "i" << std::endl; // 表示一个复数
    }

    // Complex add(const Complex &c) // 返回的是右值
    // {
    //     Complex result; 
    //     result.real = this->real + c.real;
    //     result.vir = this->vir + c.vir;
    //     return result;
    // }

    // 加法重载
    Complex operator+(const Complex &c) // 返回的是右值
    {
        Complex result;
        result.real = this->real + c.real;
        result.vir = this->vir + c.vir;
        return result;
    }

    // 减法重载
    Complex operator-(const Complex &c) // 返回的是右值
    {
        Complex result;
        result.real = this->real - c.real;
        result.vir = this->vir - c.vir;
        return result;
    }

    // 占位参数 区分++a 和 a++
    // ++a
    Complex &operator++() // 返回左值，需要返回引用
    {
        this->real++;
        this->vir++;
        return *this;
    }

    // a++
    Complex operator++(int) // 返回右值
    {
        Complex result = *this;
        this->real++;
        this->vir++;
        return result;
    }

    friend std::ostream& operator<<(std::ostream &os,const Complex& c);
    friend std::istream& operator>>(std::istream &is,Complex& c);

private:
    int real; // 实部
    int vir;  // 虚部
};

// void operator<<(std::ostream &os,const Complex& c)
// {
//     os << c.real << "+" << c.vir << "i" << std::endl;
// }

// 输出运算符重载
std::ostream& operator<<(std::ostream &os,const Complex& c)
{
    os << c.real << "+" << c.vir << "i" << std::endl;
    return os;
}

// 输入运算符重载
std::istream& operator>>(std::istream &is,Complex& c)
{
    is >> c.real >> c.vir;
    return is;  // 可以连续输入
}

int main()
{
    Complex c1(3, 4);
    Complex c2(1, 2);
    // c1.show();
    // c2.show();

    // Complex c3 = c1.add(c2);

    Complex c3 = c1+c2;
    // Complex c3 = c1.operator+(c2); // 本质

    // Complex c3 = c1-c2;

    // Complex c3 = c1++;
    // Complex c4 = ++c2;
    // c3.show();
    // c4.show();

    // c3 << std::cout; // 本质：// c3.operator<<(std::cout); 在类内

    // std::cout<<c3; //本质：operator<<(std::cout,c3); 发生隐式转换  
    
    std::cin>>c3;
    std::cout<<c3;

    return 0;
}

// ++a给的是左值，是变量 会受到原值的影响
